- [Instructor] MATLAB performs difficult
linear algebra quickly,
but you can also perform statistical analysis
to find the average, variance, standard deviation,
and other characteristics of your data.
I'll show you how to perform those tasks in this movie.
I've just started MATLAB
and I have an empty command window,
so I can start typing in my values.
I'll call my data vector one, so vec1,
equal for assignment,
then a left square bracket
and I'll type in the values four, 21, nine.
Don't need a comma.
You can use them,
but if you're not using them to separate your values
from the start,
then you shouldn't as you go on.
Then 31, nine, and 14.
And repeating the nine is intentional.
So everything looks good.
Press Enter, and there are my values.
If I want to find the arithmetic average or mean
of these six values,
then I can use the mean function.
That's M-E-A-N followed by a left parentheses,
and my vector name is vec1, Enter,
and I get an average of 14 and two thirds,
14.6667 rounded to four decimal places.
I can also calculate the variance,
and that is a measure of how spread apart my data is.
So the average is 14 and two-thirds,
and what I'd like to do is discover as a whole
how spread out the data is from that average.
The variance function is var, V-A-R,
left parentheses vec1,
right parentheses Enter,
and I see that it is 97.0667.
Variance is used in some statistical analysis,
but standard deviation is used quite a bit more.
Standard deviation is the square root of the variance,
so we can either take the square root of the variance,
which would be sqrt of var of vec1,
and then close out both sets of parentheses and Enter.
We get 9.8522.
Or we can do it in one go using the std
or standard deviation function.
So std, vec1 in parentheses, Enter,
and we get the same answer,
which is as expected.
If you're performing a statistical analysis,
you will find that about 60% of values
are within one standard deviation of the average
and then about 95% are within two
and 99% are within three.
Two other measures that you can use
are the median and the mode.
The median is the middle value in a list
if you sort the list into ascending or descending order.
If there are an odd number of values in the list,
then the median is the middle.
So if you had seven values,
the median would be the fourth
after you sort the data into ascending or descending order.
On the other hand,
if you have an even number of values,
like we have here,
then it will be the average of the two middle values.
So we have six.
That means that the median will be the average
of values three and four.
The function name, as you might expect, is median,
M-E-D-I-A-N,
left parentheses, vec1,
right parentheses, Enter.
So the median appears to be 11.5,
the average of the two middle values.
You can also identify the most common value,
which in this case is the number nine.
That most common value is called the mode.
So M-O-D-E, left parentheses, vec1,
right parentheses, Enter,
and we get the expected value of nine.
If no value occurs more than any other,
then the mode function returns the minimum.
Mode is especially useful if you want to identify
perhaps the most common survey response.
If you have a one to seven survey range
and you want to identify the most common answer,
then mode will find that information for you.